﻿using AiBLSmartEdu.Module.Role.API.DTOs;
using AiBLSmartEdu.Module.Role.API.Services;
using Application.Commons.Data;
using Application.Features.Groups.Repositories;
using FrameworkCore.Attributes;
using FrameworkCore.Controllers;
using FrameworkCore;
using Microsoft.AspNetCore.Mvc;

namespace AiBLSmartEdu.Module.Role.API.Controllers;

/// <summary>
/// 角色管理
/// </summary>
public partial class RoleController : BaseModuleController
{
    private readonly RoleServices _roleServices;
    private readonly GroupServices _groupServices;

    public RoleController(
        RoleServices roleServices,
        GroupServices groupServices)
    {
        _roleServices = roleServices;
        _groupServices = groupServices;
    }


    /// <summary>
    /// 创建角色
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost]
    [SaveChanges<EfCoreDbContext>()]
    public async Task<Result> Post(CreateRoleInputModel input)
    {
        await _roleServices.CreateAsync(input);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 修改角色
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPut]
    [SaveChanges<EfCoreDbContext>()]
    public async Task<Result> Put(UpdateRoleInputModel input)
    {
        await _roleServices.UpdateAsync(input);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 删除角色
    /// </summary>
    ///  <param name="ids">唯一标识，多个使用英文状态下的逗号（,）隔开</param>
    /// <returns></returns>
    [HttpDelete("{ids}")]
    public async Task<Result> Delete(string ids)
    {
        await _groupServices.DeleteAsync(ids);
        return await Result.SucceedAsync();
    }
}